package com.janson.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.janson.entity.Say;
import com.janson.service.impl.SayServiceImpl;
import com.janson.utils.MyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.crypto.interfaces.PBEKey;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author janson
 * @since 2022-03-31
 */
@Controller
public class SayController {
    private boolean flag = false;
    @Autowired
    private SayServiceImpl sayService;
    @GetMapping("/say")
    public String toSay(Model model){
        List<Say> sayList = sayService.list(null);
        model.addAttribute("sayList",sayList);
        if (flag){
            model.addAttribute("issueSuccess","发布成功！");
            flag = false;
        }
        return "page/say";
    }

    @PostMapping("/say/{roleId}")
    public String issueSay(@PathVariable int roleId,Say say){

        if (roleId != 1){
            MyUtils.print("非法发布公告！！！");
        }
        //say.setId(MyUtils.getUID());
        say.setGmtCreate(MyUtils.getTime());

        //存储数据到数据库
        boolean save = sayService.save(say);
        flag = true;
        return "redirect:/say";
    }
}

